package com.city.repository.party;

import com.city.domain.party.PartyStudent;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @author  王宇
 * @date 2018/8/12
 * @description  学生类dao层
 */
public interface PartyStudentRepository extends JpaRepository<PartyStudent,Integer>{

    //通过时间戳查找学生
    @Query(value = "select * from party_student where time = ?1",nativeQuery = true)
    PartyStudent findByTime(String time);

    //分页查询
    @Query(value = "select * from party_student limit ?1,?2",nativeQuery = true)
    List<PartyStudent> findByPage(Integer page,Integer limit);

    //更新数据库信息
    @Query(value = "update party_student set unlearned = " +
            "(select count(*) from party_student_lesson " +
            "where status = 0 and party_student.id = party_student_lesson.student_id )",nativeQuery = true)
    void updateUnleaned();

    @Query(value = "update party_student set have_learn" +
            " = (select count(*) from party_student_lesson " +
            "where status = 1 and party_student.id = party_student_lesson.student_id )",nativeQuery = true)
    void updateHaveleaned();

}
